﻿Public Class FrmModifFormulaire
    Dim macnx As New PPE3.ClassMySqlConnect("853339_depanneur", "071064")
    Dim position As Integer
    Dim nbchamps As Integer = 0
    Dim nom As String
    Private Sub BtnModif_Click(sender As System.Object, e As System.EventArgs) Handles BtnModif.Click
        ' BtnModif.BackColor = Color.Green
        Try
            If BtnModif.Text = "Modifier" Then
                BtnModif.Text = "Valider!"
                TextBoxInfo.Enabled = True
            Else
                If TextBoxInfo.Text <> "" Then
                    nom = RemplaceApostrophesSlash(TextBoxInfo.Text)
                    macnx.Se_Connecter_MySqlServer()
                    macnx.Executer_Requete_Action("update InfoFormulaire Set TexteInfo ='" & nom & "' where NumeroInfo = 1;")
                    MessageBox.Show("Information Modifié...!", "Alerte!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    BtnModif.Text = "Modifier"
                    'BtnModif.BackColor = Color.Red
                    macnx.Se_Deconnecter_MySqlServer()
                    TextBoxInfo.Enabled = False

                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BtnInfo2_Click(sender As System.Object, e As System.EventArgs) Handles BtnModif2.Click
        ' BtnModif2.BackColor = Color.Green
        Try
            If BtnModif2.Text = "Modifier" Then
                BtnModif2.Text = "Valider!"
                TextBoxInfo2.Enabled = True
            Else
                If TextBoxInfo2.Text <> "" Then
                    nom = RemplaceApostrophesSlash(TextBoxInfo2.Text)
                    macnx.Se_Connecter_MySqlServer()
                    macnx.Executer_Requete_Action("update InfoFormulaire Set TexteInfo ='" & nom & "' where NumeroInfo = 2;")
                    MessageBox.Show("Information Modifié...!", "Alerte!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    BtnModif2.Text = "Modifier"
                    ' BtnModif2.BackColor = Color.Red
                    macnx.Se_Deconnecter_MySqlServer()
                    TextBoxInfo2.Enabled = False

                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub FrmModifFormulaire_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = FrmStart
        Me.Top = 0
        Me.Left = 0
        macnx.Se_Connecter_MySqlServer()
        RafraichirInfo()
        macnx.Se_Deconnecter_MySqlServer()

    End Sub

    Public Sub RafraichirInfo()
        Dim donnees As New Data.DataTable
        macnx.viderVue("TexteInfo1")
        donnees = macnx.Executer_Requete_Select("SELECT TexteInfo FROM InfoFormulaire where NumeroInfo = 1 ", "TexteInfo")
        nbchamps = donnees.Rows.Count - 1
        TextBoxInfo.Text = RemplaceSlashApostrophes(macnx.GetChamp_DataTable(donnees, position, 0))
        macnx.viderVue("TexteInfo2")
        donnees = macnx.Executer_Requete_Select("SELECT TexteInfo FROM InfoFormulaire where NumeroInfo = 2", "TexteInfo2")
        TextBoxInfo2.Text = RemplaceSlashApostrophes(macnx.GetChamp_DataTable(donnees, position, 0))

    End Sub

    Public Function RemplaceApostrophesSlash(ByRef unechaine As String) As String
        Dim ch As String
        ch = unechaine.Replace("'", "/")
        Return ch
    End Function


    Public Function RemplaceSlashApostrophes(ByRef unechaine As String) As String
        Dim ch As String
        ch = unechaine.Replace("/", "'")
        Return ch
    End Function


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles BtnFermer.Click
        Close()
    End Sub
End Class